package com.flitsneak.designpatterns.structuralpatterns.flyweight;

import java.util.HashMap;
import java.util.Objects;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/7/14 17:34
 * @description
 */
public class Fishpond {
    private HashMap<String,Backup> backupHashMap = new HashMap<>(128);

    public Backup getBackup(String otherRequest) {
        Backup backup = backupHashMap.get(otherRequest);
        if (Objects.nonNull(backup)){
            System.out.println("具备"+backup.pickBackup(new BackupPrerequisites())+"条件的备胎男友已从鱼塘捞出");
        } else {
            backup = new ConcreteBackup(otherRequest);
            backupHashMap.put(otherRequest,backup);
        }
        return backup;
    }
}
